package commands;

import com.amazonaws.services.s3.AmazonS3;
import jesss.commands.JesssCommand;
import jesss.commands.JesssCommandFactoryImpl;
import jesss.options.JesssOptions;
import org.junit.Before;
import org.junit.Test;

import static org.mockito.Matchers.any;
import static org.mockito.Mockito.*;

/**
 * User: Lee
 * Date: 8/25/13
 * Time: 11:09 AM
 */
public class DeleteObjectCommandTests extends CommandTestsBase {


    private AmazonS3 mockS3 = mock(AmazonS3.class);
    private JesssOptions mockJesssOptions = mock(JesssOptions.class);

    @Before
    public void Setup() {
        stub(mockJesssOptions.getAmazonS3()).toReturn(mockS3);
        stub(mockJesssOptions.getCommandName()).toReturn("do");
        stub(mockJesssOptions.getShouldDisplayVerbose()).toReturn(true);
    }


    @Test
    public void CanDeleteObject() throws Exception {
        String[] args = {"-bn", "testBucket", "-k", "key"};
        JesssCommand deleteObjectCommand = JesssCommandFactoryImpl.getInstance().createCommand(mockS3, mockJesssOptions.getCommandName(), mockJesssOptions.getShouldDisplayVerbose(), args);

        deleteObjectCommand.executeCommand();
        verify(mockS3, times(1)).deleteObject(any(String.class), any(String.class));
    }

    @Test(expected=org.apache.commons.cli.MissingArgumentException.class)
    public void ThrowForMissingBucketParam() throws Exception {
        String[] args = {"-k", "testPrefix"};
        JesssCommand deleteObjectCommand = JesssCommandFactoryImpl.getInstance().createCommand(mockS3, mockJesssOptions.getCommandName(), mockJesssOptions.getShouldDisplayVerbose(), args);

        deleteObjectCommand.executeCommand();
    }

    @Test(expected=org.apache.commons.cli.MissingArgumentException.class)
    public void ThrowForMissingKeyParam() throws Exception {
        String[] args = {"-bn", "testBucket"};
        JesssCommand deleteObjectCommand = JesssCommandFactoryImpl.getInstance().createCommand(mockS3, mockJesssOptions.getCommandName(), mockJesssOptions.getShouldDisplayVerbose(), args);

        deleteObjectCommand.executeCommand();
    }

}
